package adapters;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.administrator.newxlmedical.R;


/**
 * Created by Administrator on 2018/5/10.
 */

public class CountSpinnerAdapter extends ArrayAdapter {
    private Context mContext;
    private String[] mData;
    private TextView tv;
    private int select;
    public CountSpinnerAdapter(@NonNull Context context, int resource, @NonNull String[] data) {
        super(context, resource, data);
        mContext = context;
        mData = data;
    }
    public CountSpinnerInterface countSpinnerInterface;

    public void setSelectPosition(int position){
        select = position;
    }

    @Override
    public int getCount() {
        return mData.length;
    }

    @Override
    public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.spinner_text, null);
        tv = (TextView) view.findViewById(R.id.spinner_text);
        View v = view.findViewById(R.id.spinner_v);
        tv.setText(mData[position]);

        if (position == select) {
            tv.setTextColor(mContext.getResources().getColor(R.color.setting_selector_color));
        }
        if (position == mData.length - 2){
            v.setVisibility(View.GONE);
        }
        if (position == 0){
            if (countSpinnerInterface != null) {
                countSpinnerInterface.onClick();
            }
        }
        return view;
    }

    public void setOnClick(CountSpinnerInterface countSpinnerInterface){
        this.countSpinnerInterface = countSpinnerInterface;
    }

    public interface CountSpinnerInterface {
        void onClick();
    }

}
